package com.ruoyi.project.module.application.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.application.domain.Application;
import com.ruoyi.project.module.application.service.IApplicationService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 配置应用管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-06
 */
@Controller
@RequestMapping("/module/application")
public class ApplicationController extends BaseController
{
    private String prefix = "module/application";
	
	@Autowired
	private IApplicationService applicationService;
	
	@RequiresPermissions("module:application:view")
	@GetMapping()
	public String application()
	{
	    return prefix + "/application";
	}
	
	/**
	 * 查询配置应用管理列表
	 */
	@RequiresPermissions("module:application:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Application application)
	{
		startPage();
        List<Application> list = applicationService.selectApplicationList(application);
		return getDataTable(list);
	}
	
	/**
	 * 新增配置应用管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存配置应用管理
	 */
	@RequiresPermissions("module:application:add")
	@Log(title = "配置应用管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Application application)
	{		
		return toAjax(applicationService.insertApplication(application));
	}

	/**
	 * 修改配置应用管理
	 */
	@GetMapping("/edit/{configApplicationId}")
	public String edit(@PathVariable("configApplicationId") Long configApplicationId, ModelMap mmap)
	{
		Application application = applicationService.selectApplicationById(configApplicationId);
		mmap.put("application", application);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存配置应用管理
	 */
	@RequiresPermissions("module:application:edit")
	@Log(title = "配置应用管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Application application)
	{		
		return toAjax(applicationService.updateApplication(application));
	}
	
	/**
	 * 删除配置应用管理
	 */
	@RequiresPermissions("module:application:remove")
	@Log(title = "配置应用管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(applicationService.deleteApplicationByIds(ids));
	}
	
}
